@isTest
private class QuoteControllerTest {
    static testMethod void testMethod1() {
        // 客户
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;

      
        // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;
        Id rt = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        // 产品
        Product__c p = TestUtils.createProduct();
        p.Purpose__c = '仪器报价用';
        p.bggsjhdj__c = 10.0;
        p.RecordTypeId = rt;

        
        Product__c p2 = TestUtils.createProduct();
        p2.Name = 'aaaa';
        p2.Purpose__c = '仪器报价用';
        p2.bggsjhdj__c = 10.0;
        p2.RecordTypeId = rt;
        insert new Product__c[] {p, p2};

        // 意向产品
        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        ip.Product__c = p.Id;
        insert ip;

        // 价格
        Price__c price = TestUtils.createPrice();
        price.Product__c = p.Id;
        price.Company__c = '四川省迈克实业有限公司';
        price.InstCost__c = 10.0;
        Price__c price2 = TestUtils.createPrice();
        price2.Product__c = p2.Id;
        price2.Company__c = '四川省迈克实业有限公司';
        price2.InstCost__c = 10.0;
        insert new Price__c[] {price, price2};
        
            /// 日期处理
        Integer m = Date.today().month(); //当前月份
        Integer y = Date.today().year();  //当前年份 
       ///取上月
         if(m == 1){
        m = 12 ;
            y -= 1;
        }else{
        m -= 1;
            
        }
        
        String  month = String.valueOf(m) + '月';
        String  year= String.valueOf(y) + '年';
        AveragePrice__c av1 = new AveragePrice__c(
        Product__c = p.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month

            
        );
          AveragePrice__c av2 = new AveragePrice__c(
       		 Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month
            
        );
        insert new AveragePrice__c[] {av2,av1};

        // ---------------------新建-----------------------
        PageReference page = new PageReference('/apex/Quote?oppid=' + opp.Id + '&t=y');
        System.Test.setCurrentPage(page);
        QuoteController qc = new QuoteController(new ApexPages.StandardController(new Quote()));

        qc.init();
        System.assertEquals(0, qc.pbList.size());
        //System.assertEquals(1, qc.qpbList.size());

        qc.name = 'aaaa';
        qc.brand = '济南希森美康';
        qc.serial = 'ZG801009';
        qc.category0 = '试剂';
        qc.category1 = '临检';
        qc.search();

        System.assertEquals(1, qc.pbList.size());

        qc.pbList[0].chk = true;
        qc.exchange();
        System.assertEquals(1, qc.qpbList.size());
        System.Test.startTest();
        qc.save();
        
        List<Quote> q = [select Id,Status from Quote where OpportunityId = :opp.Id];
        System.assertEquals(1, q.size());

        // ---------------------编辑-----------------------
        page = new PageReference('/apex/Quote?id=' + q[0].Id);
        System.Test.setCurrentPage(page);
        qc = new QuoteController(new ApexPages.StandardController(q[0]));

        qc.init();
        System.assertEquals(0, qc.pbList.size());
        System.assertEquals(1, qc.qpbList.size());

        QuoteProductPDFController pdf = new QuoteProductPDFController(new ApexPages.StandardController(q[0]));
        q[0].Status='已批准';
        update q ;
        delete q ;
    }
}